package com.five.service.impl;

import com.five.mapper.NovelMapper;
import com.five.mapper.ReadHistoryMapper;
import com.five.pojo.Novel;
import com.five.pojo.ReadHistory;
import com.five.service.IReadHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class IReadHistoryServiceImpl implements IReadHistoryService {

    @Autowired
    private ReadHistoryMapper readHistoryMapper;
    @Autowired
    private NovelMapper novelMapper;

    /**
     * 添加阅读历史
     */

    @Override
    public void addReadHistory(Long readId, Long novelId) {
        ReadHistory readHistory = new ReadHistory();
        //查询当前阅读小说的小说Id
        readHistory.setReaderId(readId);
        readHistory.setChapterId(1L);
        readHistory.setReadTime(1);
        readHistory.setNovelId(novelId);
        readHistory.setCreateTime(LocalDateTime.now());
        readHistoryMapper.addReadHistory(readHistory);

    }

    /**
     * 删除阅读历史
     */
    @Override
    public void deleteReadHistory( Long readId, List<Long> novelId) {
        readHistoryMapper.deleteReadHistory( readId, novelId);
    }

    /**
     * 查询一周以内阅读历史
     */
    @Override
    public List<ReadHistory> queryReadHistory(Long readId) {
        return readHistoryMapper.queryReadHistory(readId);

    }
}